package com.icloud.framework.exception;



import org.springframework.http.HttpStatus;
import org.springframework.validation.FieldError;

import java.util.ArrayList;
import java.util.List;

/**
 * 所有异常都将返回该错误对象
 */
public class ValidError {
	private HttpStatus status;
	private List<ValidFieldError> fieldErrors;
	private String exception;
	public ValidError() {
	}

	public ValidError(List<FieldError> errors) {
		status = HttpStatus.BAD_REQUEST;
		fieldErrors = new ArrayList<ValidFieldError>();
		for (FieldError error : errors) {
			fieldErrors.add(new ValidFieldError(error));
		}
	}

	public HttpStatus getStatus() {
		return status;
	}

	public int getStatusCode(){
		return this.status.value();
	}

	public String getException(){
		return this.exception;
	}

	public List<ValidFieldError> getFieldErrors() {
		return fieldErrors;
	}

	public long getTimestamp(){
		return System.currentTimeMillis();
	}
}
